﻿using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.DHQG;
using DHQGHN.DAL.Models.Admin;
using DHQGHN.DAL.Models.DHQG;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DHQGHN.DAL.BO.DHQG
{
    public class DonViBO : BaseBO
    {
        private DonViDAO _dao;
        public const string DON_VI_ID = "DON_VI_ID";
        public const string NHOM_DON_VI_ID = "NHOM_DON_VI_ID";
        public const string TEN_NHOM_DON_VI = "TEN_NHOM_DON_VI";
        public const string MA_DON_VI = "MA_DON_VI";
        public const string DON_VI = "DON_VI";
        public const string CO_QUYEN_GIAM_SAT = "CO_QUYEN_GIAM_SAT";        
        public const string GHI_CHU = "GHI_CHU";
        public const string RECORD_COUNT = "RECORD_COUNT";
        public const string TEN_VIET_TAT = "TEN_VIET_TAT";
        public DonViBO()
        {
            _dao = new DonViDAO(Common.ConnectionUtil.DHQGHN_CONNECTION_STRING, DEFAULT_MAPPER_TYPE);
        }

        public DonViBO(string connectionString)
        {
            _dao = new DonViDAO(connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<DonVi> GetListPaging(DonVi model, int pageIndex, int pageSize)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetListPaging(model, pageIndex, pageSize, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public DonVi GetById(int id)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetById(id, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public bool Save(DonVi model)
        {
            try
            {
                return _dao.Save(model);
            }
            catch
            {
                throw;
            }
        }

        public bool SaveNhomDonVi(int DonViId, int NhomDonViId, List<int> NhomDonViKhac)
        {
            try
            {
                return _dao.SaveNhomDonVi(DonViId, NhomDonViId, NhomDonViKhac);
                
            }
            catch
            {
                throw;
            }
        }

        public bool SaveGroups(int DonViId, List<int> lstGroupID)
        {
            try
            {
                return _dao.SaveGroups(DonViId, lstGroupID);

            }
            catch
            {
                throw;
            }
        }

        //public bool Delete(int id)
        //{
        //    try
        //    {
        //        return _dao.Delete(id);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //}

        //phunx1, 20160420: method lay tat ca cac don vi theo nhomDVID
        public List<DonVi> GetAllDonViByNhom(int nhomDVID)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetAllDonViByNhom(nhomDVID, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        //phunx1, 20160420: method lay tat ca cac don vi co ban theo nhomDVID
        public List<DonVi> GetAllDonViCoBanByNhom(int nhomDVID)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetAllDonViCoBanByNhom(nhomDVID, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public List<DonVi> GetDonViByType(bool isGiamSat)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetDonViByType(isGiamSat, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public List<DonVi> GetDonViByUserName(string UserName)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetDonViByUserName(UserName, mapDictionary);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        //vanduong, 20160430
        public List<DonVi> GetAll()
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetAll(mapDictionary);
            }
            catch
            {

                throw;
            }
        }

        public List<DonVi> GetGroupByDonViID(int intDonViID)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetGroupByDonViID(intDonViID, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public List<DonVi> GetListDonViInCommentTable(int namKhId, int statusId)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetListDonViInCommentTable(namKhId, statusId, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public List<DonVi> GetListDonViDeXuatDieuChinh(int namKhId)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();

                return _dao.GetListDonViDeXuatDieuChinh(namKhId, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public List<DonVi> GetListDonViKhongDeXuatDieuChinh(int namKhId)
        {
            Dictionary<string, string> mapDictionary = GetMapDictionary();

            return _dao.GetListDonViKhongDeXuatDieuChinh(namKhId, mapDictionary);
        }

        private Dictionary<string, string> GetMapDictionary()
        {
            Dictionary<string, string> mapDictionary = new Dictionary<string, string>()
            {
                {DonVi.DON_VI_ID, DonViBO.DON_VI_ID},
                {DonVi.DON_VI, DonViBO.DON_VI},
                {DonVi.NHOM_DON_VI_ID, DonViBO.NHOM_DON_VI_ID},
                {DonVi.TEN_NHOM_DON_VI, DonViBO.TEN_NHOM_DON_VI},
                {DonVi.MA_DON_VI, DonViBO.MA_DON_VI},
                {DonVi.CO_QUYEN_GIAM_SAT_INT, DonViBO.CO_QUYEN_GIAM_SAT},//vanduong2016011
                {DonVi.GHI_CHU,DonViBO.GHI_CHU},
                {DonVi.RECORD_COUNT,DonViBO.RECORD_COUNT},
                {DonVi.TEN_VIET_TAT,DonViBO.TEN_VIET_TAT},
            };

            return mapDictionary;
        }
    }
}
